package com.cxm.support.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cxm.support.entity.Forum;
import com.cxm.support.service.CommentService;
import com.cxm.support.service.ForumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cxm
 * @since 2022-06-03
 */
@Controller
@RequestMapping("/support")
public class ForumController {
    @Autowired
    private ForumService forumService;
    @Autowired
    private CommentService commentService;






    @GetMapping("/forumlist")
    public ModelAndView redirect11() {
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.setViewName("forumlist");
        List<Forum> list = forumService.list();
        modelAndView.addObject("list",list);
        return modelAndView;
    }


    @GetMapping("/forumdetail/{id}")
    public ModelAndView redirect12 (@PathVariable("id") Integer id) {
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.setViewName("forumdetail");
        Forum forum = forumService.getById(id);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("forumid",id);
        List commentlist = commentService.list(wrapper);
        modelAndView.addObject("forum",forum);
        modelAndView.addObject("commentlist",commentlist);
        return modelAndView;
    }

}

